﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_MNY_BATCH_Mny4011b_Delete_Monthly_Close_Data')
	BEGIN
		DROP Procedure usp_UPDMS_MNY_BATCH_Mny4011b_Delete_Monthly_Close_Data
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_MNY_BATCH_Mny4011b_Delete_Monthly_Close_Data
**	Desc : 월마감된 데이터를 마감취소(삭제)한다
**	Test Exec Query : Exec usp_UPDMS_MNY_BATCH_Mny4011b_Delete_Monthly_Close_Data
**	Called by : Mny_Dac_UPDMS_MNY_BATCH_Mny4011b.cs
**	Program ID : Mny4011b
**	Auth : 송시명
**	Date : 2011-07-01
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_MNY_BATCH_Mny4011b_Delete_Monthly_Close_Data]
@ls_base_ym nvarchar(7)
AS
SET NOCOUNT OFF

DELETE FROM UPDMS_MNY_IN_OUT_MGT
 WHERE Seq IN (
         --마감월의 마감된 데이터
         SELECT Seq
           FROM UPDMS_MNY_IN_OUT_MGT WITH(NOLOCK)
          WHERE LEFT(Reg_Dt, 7) = @ls_base_ym
            AND Close_Yn = 'Y'
         UNION
         --마감월 다음월의 마감된 데이터 (잔액 전월이월)
         SELECT Seq
           FROM UPDMS_MNY_IN_OUT_MGT WITH(NOLOCK)
          WHERE Reg_Dt = dbo.ufn_UPDMS_Get_Date_Add ('M', 1, @ls_base_ym + '-01')
            AND Close_Yn = 'Y'
            AND Class = 'AA001'
            AND Account = 'AB996'
       )

GO